package com.tangsm.spring.boot.springdoc.api;

import com.tangsm.spring.boot.springdoc.domain.base.Result;
import com.tangsm.spring.boot.springdoc.domain.dto.User;
import com.tangsm.spring.boot.springdoc.exception.BusinessException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 用户管理接口API
 *
 * @author tangsm
 * @date 2021-07-27 16:33:01
 */
@Tag(name = "UserApi", description = "用户管理接口")
public interface UserApi {
    /**
     * 查询所有记录
     *
     * @return 通用返回对象，查询数据data获取
     */
    @Operation(summary = "查询所有记录",
            description = "查询所有记录",
            responses = {
                    @ApiResponse(description = "返回添加的用户", content = @Content(mediaType = "application/json", schema = @Schema(anyOf = {Result.class, User.class}))),
                    @ApiResponse(responseCode = "400", description = "返回400时候错误的原因")
            }
    )
    Result<List<User>> listAll();

    /**
     * 根据主键查询
     *
     * @param id 主键
     * @return 通用返回对象，查询数据data获取
     */
    @Operation(summary = "根据主键查询",
            description = "根据主键查询",
            parameters = {
                @Parameter(name = "id", description = "ID")
            },
            responses = {
                @ApiResponse(description = "返回添加的用户", content = @Content(mediaType = "application/json", schema = @Schema(anyOf = {Result.class, User.class}))),
                @ApiResponse(responseCode = "400", description = "返回400时候错误的原因")
            }
    )
    Result<User> getById(@PathVariable(value = "id") Long id);

    /**
     * 新增，忽略null字段
     *
     * @param user 新增的记录
     * @return 通用返回对象，返回影响行数
     */
    @Operation(summary = "新增的记录",
            description = "新增的记录，忽略null字段",
            responses = {
                    @ApiResponse(description = "返回添加的用户", content = @Content(mediaType = "application/json", schema = @Schema(anyOf = {Result.class, Integer.class}))),
                    @ApiResponse(responseCode = "400", description = "返回400时候错误的原因")
            }
    )
    Result<Integer> insert(@RequestBody User user) throws BusinessException;

    /**
     * 修改，忽略null字段
     *
     * @param user 修改的记录
     * @return 通用返回对象，返回影响行数
     */
    @Operation(summary = "修改的记录",
            description = "修改的记录，忽略null字段",
            responses = {
                    @ApiResponse(description = "返回添加的用户", content = @Content(mediaType = "application/json", schema = @Schema(anyOf = {Result.class, Integer.class}))),
                    @ApiResponse(responseCode = "400", description = "返回400时候错误的原因")
            }
    )
    Result<Integer> update(@RequestBody User user);

    /**
     * 删除记录
     *
     * @param id 删除的记录ID
     * @return 通用返回对象，返回影响行数
     */
    @Operation(summary = "删除记录",
            description = "删除记录，根据ID删除",
            responses = {
                    @ApiResponse(description = "返回添加的用户", content = @Content(mediaType = "application/json", schema = @Schema(anyOf = {Result.class, Integer.class}))),
                    @ApiResponse(responseCode = "400", description = "返回400时候错误的原因")
            }
    )
    Result<Integer> delete(@PathVariable(value = "id") Long id);
}
